def solution(a, b):
    # write code here
    result = []

    if len(a) != len(b):
        min_arr = a if len(a) < len(b) else b
        max_arr = a if len(a) > len(b) else b
        for i in range(len(min_arr)):
            if min_arr[i] in max_arr:
                result.append(min_arr[i])
    else:
        for i in range(len(a)):
            if a[i] in b:
                result.append(a[i])
    return sorted(result, reverse=True)


if __name__ == '__main__':
    print(solution([1, 2, 3, 7], [2, 5, 7]) == [7, 2])
    print(solution([1, 4, 8, 10], [2, 4, 8, 10]) == [10, 8, 4])
    print(solution([3, 5, 9], [1, 4, 6]) == [])
    print(solution([1, 2, 3], [1, 2, 3]) == [3, 2, 1])